package cn.fxyz.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import cn.fxyz.dao.impl.OrderDaoImpl;
import cn.fxyz.dao.impl.OrderDetailDaoImpl;
import cn.fxyz.dao.impl.UserDaoImpl;
import cn.fxyz.entity.Dinnertable;
import cn.fxyz.entity.Food;
import cn.fxyz.entity.Orderdetail;
import cn.fxyz.entity.Orders;
import cn.fxyz.entity.User;
import cn.fxyz.page.PageBean;
import cn.fxyz.service.OrderService;

public class OrderServiceImpl implements OrderService {
	private OrderDaoImpl orderDaoImpl;
	private OrderDetailDaoImpl orderDetailDaoImpl;
	private UserDaoImpl userDaoImpl;
	
	public UserDaoImpl getUserDaoImpl() {
		return userDaoImpl;
	}

	public void setUserDaoImpl(UserDaoImpl userDaoImpl) {
		this.userDaoImpl = userDaoImpl;
	}

	public OrderDetailDaoImpl getOrderDetailDaoImpl() {
		return orderDetailDaoImpl;
	}

	public void setOrderDetailDaoImpl(OrderDetailDaoImpl orderDetailDaoImpl) {
		this.orderDetailDaoImpl = orderDetailDaoImpl;
	}

	public OrderDaoImpl getOrderDaoImpl() {
		return orderDaoImpl;
	}

	public void setOrderDaoImpl(OrderDaoImpl orderDaoImpl) {
		this.orderDaoImpl = orderDaoImpl;
	}
	//商家操作
	public PageBean<Orders> findAll(int pageNum) {
		PageBean<Orders> page=new PageBean<Orders>(pageNum, orderDaoImpl.getTotalRecord("", new String[]{}));
		List<Orders> list=orderDaoImpl.selectAll("", new String[]{}, page.getStartIndex(), page.getPageSize());
		page.setData(list);
		return page;
	}

	public Orders findByOrderId(int orderId) {
		return orderDaoImpl.selectById(orderId);
	}
	
	public int modifyStatusByOrderId(int orderId) {
		Orders o=orderDaoImpl.selectById(orderId);
		if(o.getOrderstatus()==0)
		o.setOrderstatus(1);
		else o.setOrderstatus(0);
		return 1;
	}
	
	//用户下单
	///////////////////////此处要大改动
	/*public void addOrder(Object user, Object dinnerTable, Object foods,float price) {
		List<Food> f = (ArrayList<Food>) foods;
		//把食物对象存入订单详情对象
		Orders order=new Orders();
		Set<Food> fs = new HashSet<Food>(foodList);  
		Set<Orderdetail> details = new HashSet<Orderdetail>();
		//把所有信息存入订单对象
	
		order.setDinnertable((Dinnertable)dinnerTable);
		order.setTotalprice(price);
		order.setOrderstatus(0);
		order.setOrderdate(new Date());
		order.setUser((User)user);
		//在detail表插入数据
		System.out.println("未进入for循环");
		for(int i=0;i<f.size();i++){
			System.out.println("进入for循环");
			Orderdetail d=new Orderdetail();
			System.out.println(111);
			d.getFood().setId(f.get(i).getId());
			System.out.println(222);
			d.setFoodcount(f.get(i).getNum());
			System.out.println(333);
			details.add(d);
			System.out.println("有一条数据");
		}
		for(Food f1:f){
			System.out.println(f1);
		}
		order.setOrderdetails(details);
		System.out.println("准备插入");
		orderDaoImpl.insert(order);
		System.out.println("插入成功");
	}*/

	public void add(Orders order) {
		orderDaoImpl.insert(order);
	}

	public void addOrder(Object user, Object dinnerTable, Object foods, float price) {
		// TODO Auto-generated method stub
		
	}
}
